package main;

import util.Operations;
import util.Util;
import modulos.Marking;
import modulos.Morphology;
import modulos.PreProcessing;


public class Main {
	static final String DIRETORIO_PREPROCESSING = "\\preprocessing\\";
	static final String DIRETORIO_MARKING = "\\marking\\";
	static final String DIRETORIO_MORHOLOGY = "\\morphology\\";
	static final String EXEMPLO = "base\\exemplo";
	static final String BACKGROUND_IMAGE = "base\\background\\background25.jpg";
	static final String FOREGROUND_IMAGE = "\\foreground\\foreground25.jpg";
	
	public static void main(String[] args) {
		
		int qtdExemplos = 7;
		
		//commitar
		System.out.println("iniciando o programa.");
		double[][] backgroundImage = null;
		double[][] foregroundImage = null;
		
		try {
			for(int i=1;i<=qtdExemplos;i++)
			{
				//niclack -> 0.4 17
				double[][][] background = Util.lerImagemColorida(BACKGROUND_IMAGE);
				backgroundImage = PreProcessing.imageGraying(background);
				
				double[][][] foreground = Util.lerImagemColorida(EXEMPLO+i + FOREGROUND_IMAGE);
				foregroundImage = PreProcessing.imageGraying(foreground);
				
				/*
				//	fica praticamente imune a variacao de treshold... nao adianta muito pra gente.
				for(int j=30;j<=150;j+=10)
				{
					double[][][] subtracted = PreProcessing.backgroundSubtraction(background, foreground, j);
					double[][] preprocessed = PreProcessing.imageGraying(subtracted);
					Util.salvaImagem(EXEMPLO + "PASSO1-Threshold" + j + ".jpg", preprocessed);
				}
				*/

				for(int threshold=90;threshold<=90;threshold+=10)
				{
					
					/*
					double[][][] subtracted = PreProcessing.backgroundSubtraction(background, foreground, j);
					double[][] preprocessed = PreProcessing.imageGraying(subtracted);
					*/
					
					double[][] preprocessed = PreProcessing.start(EXEMPLO+i+DIRETORIO_PREPROCESSING, background, foreground, threshold);//PreProcessing.start(EXEMPLO + i + DIRETORIO_PREPROCESSING, backgroundImage, foregroundImage, threshold);
					
					for(int qtdDilatacoes=4;qtdDilatacoes<5;qtdDilatacoes++)
					{
						double[][] fixed = Morphology.start(EXEMPLO+i + DIRETORIO_MORHOLOGY+qtdDilatacoes, preprocessed, threshold, qtdDilatacoes);
						Marking.start(EXEMPLO + i + DIRETORIO_MARKING, foreground, fixed, threshold, qtdDilatacoes);
						
					}					
				}
				
				
				/*FUNCIONANDO
				for(int threshold=100;threshold<=100; threshold = threshold+10)
				{
					double[][] preprocessed = PreProcessing.start(EXEMPLO + i + DIRETORIO_PREPROCESSING, backgroundImage, foregroundImage, threshold);
					
					for(int qtdDilatacoes=5;qtdDilatacoes<=5;qtdDilatacoes=qtdDilatacoes+5)
					{
						double[][] fixed = Morphology.start(EXEMPLO+i + DIRETORIO_MORHOLOGY+qtdDilatacoes, preprocessed, threshold, qtdDilatacoes);
						Marking.start(EXEMPLO + i + DIRETORIO_MARKING, foregroundImage, fixed, threshold, qtdDilatacoes);
						
					}					
				}
				*/
			}
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally	{
			System.out.println("fim do processo.");
		}
		
	}
}
